home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDDiscTitle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  3.9 KB  |  148 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDDiscTitle - An XFCN to report the title of the disc, if one has been entered
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C CDDiscTitle.c
  11.     link -sn Main=CDDiscTitle -sn STDIO=CDDiscTitle ∂
  12.          -sn INTENV=CDDiscTitle -rt XFCN=42 ∂
  13.          -m CDDISCTITLE CDDiscTitle.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25. #include <ToolUtils.h>
  26.  
  27. /* prototype definitions for functions */
  28. OSErr    FindTitle(unsigned long, Str255    *);
  29.  
  30. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  31.  
  32.  
  33. /************************************************************************
  34.  *
  35.  *  Function:        CDDiscTitle
  36.  *
  37.  *  Purpose:        return the title of this disc.
  38.  *
  39.  *  Returns:        a string, or empty
  40.  *
  41.  *  Side Effects:
  42.  *
  43.  *  Description:    We need no parameters:
  44.  *                    Get the ioRefNum that we got from previously calling
  45.  *                    CDOpen() by accessing the famous global
  46.  *                    call the driver with a READTOC call to find out
  47.  *                    the lead-out time.  This is a unique number for each
  48.  *                    disc.  Look in the System Folder for the file
  49.  *                    "CD Remote Programs".  Open that file, look at the
  50.  *                    IndX resource to find out if we've got a matching
  51.  *                    index.  If we do, look up the STR# resource 
  52.  *                    referenced and return the first STR from that list.
  53.  *
  54.  ************************************************************************/
  55. pascal void
  56. CDDiscTitle(paramPtr)
  57. XCmdBlockPtr    paramPtr;
  58. {
  59.     OSErr    result;
  60.     short    ioRefNum;
  61.     Handle    refHandle;
  62.     unsigned long    discID;
  63.     Str255    title;
  64.     Str31    returnString;
  65.     
  66.     strcpy(title, "\p");
  67.  
  68.     /* Must be no parameters */
  69.     if ((paramPtr->paramCount) != 0)
  70.     {
  71.         /* Report error in parameters by returning -1 */
  72.         NumToStr(paramPtr, (long) -1, &returnString);
  73.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  74.         return;
  75.     }
  76.     
  77.     /* Get the global ioRefNum and convert it. */
  78.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  79.     ioRefNum = atoi(*(refHandle));
  80.     DisposHandle(refHandle);
  81.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  82.  
  83.     result = IDDisc(ioRefNum, &discID);
  84.     
  85.     if (discID == 0)
  86.         return;        /* empty string return if we can't ID the disc */
  87.     
  88.     result = FindTitle(discID, &title);
  89.     
  90.     paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &title);
  91. }
  92.  
  93.  
  94.  
  95. /************************************************************************
  96.  *
  97.  *  Function:        FindTitle
  98.  *
  99.  *  Purpose:        Find disc title, given the disc ID
  100.  *
  101.  *  Returns:        OSErr.  Usually noErr, but could have an error
  102.  *                    in opening the CD Remote Programs file.
  103.  *
  104.  *  Side Effects:    fills in title with found title
  105.  *
  106.  *  Description:    open the file "CD Remote Programs".  Look at the
  107.  *                    'IndX' resource to find out if we have a title.
  108.  *                    If we can't find the appropriate 'IndX' resource,
  109.  *                    set the title to blank and return.  If we find
  110.  *                    the appropriate IndX resource, open the associated
  111.  *                    STR# resource and return the first string.
  112.  *
  113.  ************************************************************************/
  114. OSErr
  115. FindTitle(discID, title)
  116. unsigned long    discID;
  117. Str255            *title;
  118. {
  119.     OSErr    result;
  120.     short    strListID;            /* holds the 'STR#' resource id. */
  121.     short    resFile;
  122.     Str255    fileName;
  123.     
  124.     result = noErr;
  125.     
  126.     GetIndString(fileName, STR_ID, DRIVENAME);
  127.     if (fileName == (Str255)0)
  128.         result = ResError();
  129.  
  130.     if (result == noErr)
  131.     {
  132.         resFile = OpenSystemResFile(fileName);
  133.         if (resFile == -1)
  134.             result = ResError();
  135.     }
  136.         
  137.     if (result == noErr)
  138.         if (FindIndex(discID, &strListID) == true)
  139.             GetIndString(title, strListID, 1);        /* fills in title */
  140.     
  141.     CloseResFile(resFile);
  142.     return result;
  143. }
  144.  
  145.  
  146. /* C routines for HyperCard callbacks */
  147. #include <XCmdGlue.inc.c>
  148.